package com.manxi.mapper;

import com.manxi.entity.OrderDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderDetailMapper {

    /**
     * 根据订单id查询订单详情
     * @param ordersId
     * @return
     */
    @Select("select * from order_detail where order_id = #{ordersId}")
    List<OrderDetail> getByOrderId(Long ordersId);

    /**
     * 向订单明细表中插入n条数据
     *
     * @param orderDetails
     */
    @Insert("<script>" +
            "insert into order_detail (name, order_id, dish_id, setmeal_id, dish_flavor, number, amount, image) values " +
            "<foreach collection='orderDetails' item='od' separator=','> " +
            "(#{od.name},#{od.orderId},#{od.dishId},#{od.setmealId},#{od.dishFlavor},#{od.number},#{od.amount},#{od.image})" +
            "</foreach> " +
            "</script>")
    void insertBatch(List<OrderDetail> orderDetails);

}
